package edu.zju.gis.cky.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import edu.zju.gis.cky.entity.dto.ChangeMatrixDTO;
import edu.zju.gis.cky.entity.dto.StatisticAreaByOneClassDTO;
import edu.zju.gis.cky.service.LandFlow2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RequestMapping("/flow2")
@RestController
public class LandFLow2Controller {

    @Autowired
    private LandFlow2Service service;

    @GetMapping("/getTable")
    public String[][] getTable(@RequestParam Long beginMetaId, Long endMetaId, int type, String from, String to) {
        ChangeMatrixDTO changeMatrixDTO = new ChangeMatrixDTO();
        changeMatrixDTO.setBeginMetaId(beginMetaId);
        changeMatrixDTO.setEndMetaId(endMetaId);
        changeMatrixDTO.setType(type);
        changeMatrixDTO.setFrom(from);
        if (!to.equals("")) {
            changeMatrixDTO.setTo(to);
        }
        return service.getTable(changeMatrixDTO);
    }

    @GetMapping("/getList")
    public PageInfo<JSONObject> getList(@RequestParam Long beginMetaId, Long endMetaId, int type, String from, String to, int pageNum, int pageSize,Double areaFilter) {
        ChangeMatrixDTO changeMatrixDTO = new ChangeMatrixDTO();
        changeMatrixDTO.setBeginMetaId(beginMetaId);
        changeMatrixDTO.setEndMetaId(endMetaId);
        changeMatrixDTO.setType(type);
        changeMatrixDTO.setFrom(from);
        if (!to.equals("")) {
            changeMatrixDTO.setTo(to);
        }
        return service.getList(changeMatrixDTO, pageNum, pageSize,areaFilter);
    }

    @GetMapping("/statistic")
    public JSONObject statistic(@RequestParam Long beginMetaId, Long endMetaId, int type, String from, String to) {
        ChangeMatrixDTO changeMatrixDTO = new ChangeMatrixDTO();
        changeMatrixDTO.setBeginMetaId(beginMetaId);
        changeMatrixDTO.setEndMetaId(endMetaId);
        changeMatrixDTO.setType(type);
        changeMatrixDTO.setFrom(from);
        if (!to.equals("")) {
            changeMatrixDTO.setTo(to);
        }
        return service.statistic(changeMatrixDTO);
    }

    @GetMapping("/getAreaByXZQH")
    public HashMap<String, String[][]> getAreaByXZQH(@RequestParam int type, Long beginMetaId, Long endMetaId, String code, String xzqh) {
        StatisticAreaByOneClassDTO dto = new StatisticAreaByOneClassDTO();
        dto.setBeginMetaId(beginMetaId);
        dto.setType(type);
        dto.setEndMetaId(endMetaId);
        dto.setCode(code);
        dto.setXzqh(xzqh);
        return service.getAreaByXZQH(dto);
    }
}
